#1 类的继承
# 父类
class Person:   # 默认继承object类
    def __init__(self, name, age):
        self.name = name
        self.age = age
    def show(self):
        print(f'我叫：{self.name}。今年：{self.age}岁。')
# 子类，继承父类Person
class Student(Person):
    def __init__(self, name, age, number):
        super().__init__(name, age)     # 调用父类的初始化方法
        self.number = number
class Doctor(Person):
    def __init__(self, name, age, department):
        super().__init__(name, age)
        self.department = department

# 创建子类对象
stu1 = Student('韩梅梅',20, '1001')
stu1.show()

doctor1 = Doctor('张依', 32, '外科')
doctor1.show()
print('-'*50)

#2 子类的多继承
class FatherA():
    def __init__(self, name):
        self.name = name
    def showA(self):
        print('父类A中的方法')
class FatherB():
    def __init__(self, age):
        self.age = age
    def showB(self):
        print('父类B中的方法')

class Son(FatherA, FatherB):
    def __init__(self, name, age, gender):
        FatherA.__init__(self, name)
        FatherB.__init__(self, age)
        self.gender = gender

son = Son('韩梅梅', 20, '女')
son.showA()
son.showB()
print('-'*50)

#3 方法重写-子类重写父类的方法
class Person1:
    def __init__(self, name, age):
        self.name = name
        self.age = age
    def show(self):
        print(f'我叫：{self.name}。今年：{self.age}岁。')
class Student1(Person1):
    def __init__(self, name, age, number):
        super().__init__(name, age)
        self.number = number
    def show1(self):
        super().show()  # 调用父类的方法
        print(f'学号：{self.number}')
class Doctor(Person):
    def __init__(self, name, age, department):
        Person1.__init__(self, name, age)
        self.department = department
    # 子类方法完全重写
    def show(self):
        print(f'我叫：{self.name}。今年：{self.age}岁。在{self.department}办公')

stu1 = Student1('韩梅梅',20, '1001')
stu1.show1()

doctor1 = Doctor('张依', 32, '外科')
doctor1.show()  # 当子类方法与父类方法同名时，如果子类有自己的方法，直接调用
